import React from 'react';
import {  View,Text } from 'react-native';
class Index extends React.Component{
  state={
    num:100
  }

  handlePress(){
    console.log(this.state);
    this.setState({num:++this.state.num})
  }

  //1 正确的写好 剪头函授
//   handlePress=()=>{
//   console.log(this.state);
// }

  //4 通过再构造函数中绑定事件来实现

  constructor() {
    super();
    this.handlePress=this.handlePress.bind(this);
  }
  render() {
    return <View>
      <Text onPress={this.handlePress}>{this.state.num }</Text>
      {/*2 通过bind来绑定 */}
      {/*<Text onPress={this.handlePress.bind(this)}>{this.state.num }</Text>*/}
      {/*3 匿名函数的方式 */}
      {/*<Text onPress={()=>this.handlePress()}>{this.state.num }</Text>*/}
    </View>
  }
}

export default Index;
